# 无法运行

import sys
from PyQt5.QtCore import pyqtSignal,pyqtSlot,QThread,QObject
from PyQt5 import QtCore, QtGui, QtWidgets, QtWebEngineWidgets
import folium
from folium.plugins import MousePosition, mouse_position, MeasureControl
from folium.plugins import Draw
from folium import *
from folium import plugins

import map4
import temjs

from PyQt5.uic import loadUi
from PyQt5.QtWidgets import *

import io

class Form(QWidget):
    targetSize=[0,0,0]
    tmpStl='tmp.stl'
    tmpStp='tmp.stp'
    importFile = ''
    importFileType = ''
    meshSize = 500.
    shapeModel = None
    shapeMesh = None
    vertices = None
    facets = None
    edges = None
    ratio =1
    head ='x'
    up   ='z'

    def __init__(self):
        super(Form, self).__init__()
        # 导入model.ui?

        loadUi('model.ui', self)



        self.view = QtWebEngineWidgets.QWebEngineView()
        self.verticalLayout_7.addWidget(self.view)
        self.m = folium.Map(location=[0, 0], zoom_start=6, tiles="Stamen Terrain")
        self.m.add_child(MeasureControl())
        self.m.add_child(temjs.drawcircle())

        self.fg = folium.FeatureGroup(name="全部")
        self.m.add_child(self.fg)
        self.g1 = plugins.FeatureGroupSubGroup(self.fg, "探测器")
        self.m.add_child(self.g1)
        self.g2 = plugins.FeatureGroupSubGroup(self.fg, "目标")
        self.m.add_child(self.g2)

        folium.LayerControl(collapsed=False).add_to(self.m)
        formatter = "function(num) {return L.Util.formatNum(num, 3) + ' º ';};"
        MousePosition(
            position="bottomright",
            separator=" | ",
            empty_string="NaN",
            lng_first=True,
            num_digits=20,
            prefix="Coordinates:",
            lat_formatter=formatter,
            lng_formatter=formatter,
        ).add_to(self.m)
        draw = Draw()
        draw.add_to(self.m)

        self.data = io.BytesIO()
        self.m.save(self.data, close_file=False)
        self.view.setHtml(self.data.getvalue().decode())

    # folium______________________↑____________________________________
    @pyqtSlot()
    def on_pushButtonTIANJIA_clicked(self):
        url1 = "http://m.qpic.cn/psc?/V51C95Hq1ZdheR3La0T81xYNvJ2BJ0VL/bqQfVz5yrrGYSXMvKr.cqUC1uGB.7mSwlk4dhiKVy7mNmYCSpfb1raxvdtxDw1AlvOWF*wIjRgkkF0eSWZZbDtg*nS4GAx1KPx0yNJE4Xoo!/mnull&bo=gAKrAQAAAAABBwg!&rf=photolist&t=5".format
        radar = url1('11.jfif')

        url2 = "http://m.qpic.cn/psc?/V51C95Hq1ZdheR3La0T81xYNvJ2BJ0VL/TmEUgtj9EK6.7V8ajmQrENy1otAsPNb*ErrTtVqd.cERyU4LWv6ppxn8*Rntaw2s2ZwTU8PGaDQ2j41G6fauWKLpLo3VRKsNBmfmnCAOpck!/b&bo=oAU4BAAAAAABF6k!&rf=viewer_4".format
        plane = url2('22.png')

        LALO1 = self.lineEditPOS1.text()
        LA1 = float(LALO1.split(',')[0])
        LO1 = float(LALO1.split(',')[1])

        icon = CustomIcon(
            eval(self.lineEditNAME.text()),
            icon_size=(38, 35),
            icon_anchor=(22, 0),
            popup_anchor=(0, 0),
        )
        marker = map4.Marker(
            location=[LA1, LO1],
            icon=icon,
            popup=(self.lineEditRADAR.text()),
            draggable=True)

        self.g1.add_child(marker)
        self.data = io.BytesIO()
        self.m.save(self.data, close_file=False)
        self.view.setHtml(self.data.getvalue().decode())
if __name__ == "__main__":
    app = QApplication(sys.argv)
    form = Form()
    form.show()
    sys.exit(app.exec_())
